class ItemsController < ApplicationController
  
  resource(:items, :parent => :list) do
  
    collection do
      GET do
        @items = @list.items.find(:all)
      end
    
      POST do
        @item = @list.items.build(params[:item])
        if @item.save
          redirect_to items_url(@list)
        else
          render :action => "new", :status => :bad_request
        end
      end
    end
  
    action "new" do
      GET(:html) do
        @item = @list.items.build
      end
    end

    member do
      
      find do
        @list.items.find(params[:id])
      end
    
      action "edit" do
        GET(:html)
      end
    
      GET()

      PUT(:if => :found?) do
        @item.attributes = params[:item]
        if @item.save
          redirect_to items_url(@list)
        else
          render :action => "edit", :status => :bad_request
        end
      end
    
      DELETE do
        @item.destroy if @item
        redirect_to items_url(@list)
      end
    
    end
  end

end